package com.dfd.security.config;

import com.dfd.security.filter.TimeFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class WebConfig {
    @Bean
    public FilterRegistrationBean timeFilter() {
        //初始化一个过滤器注册器
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        TimeFilter timeFilter = new TimeFilter();
        //将自定义的过滤器或者第三方过滤器注册到过滤器链中
        registrationBean.setFilter(timeFilter);

        List<String> urls = new ArrayList<>();
        urls.add("/*");
        //该过滤器对所有的url起作用，但你也可以配置专门的url进行过滤
        registrationBean.setUrlPatterns(urls);
        return registrationBean;
    }

}
